package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.AdminService;
import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.Admin;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminTurnoverController", value = "/admin/adminTurnover")
public class AdminTurnoverController extends HttpServlet {
    private AdminService adminService = null;
    public AdminTurnoverController() {
        adminService = new AdminService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        //获取当前会话中的admin对象
        Admin admin = (Admin) session.getAttribute("admin");
        //获取该admin对象的adminId
        Integer adminId = admin.getAdminId();
        //获取该admin对象的营业额
        double turnover = admin.getTurnover();
        //获取完成一个订单的营业额
        String totalP = request.getParameter("totalPrice");
        Double totalPrice = Double.valueOf(totalP);
        //修改该admin的营业额
        adminService.saveTurnover(turnover+totalPrice,adminId);

        response.sendRedirect(request.getContextPath()+"/admin/orderList?payFlag=0");

    }

}
